﻿/* Author: Achim Schnell */

using System;
using System.Collections.Generic;

namespace AppFx.Tokenization
{
    /// <summary>
    /// Verifies single-char symbols for tokens.
    /// </summary>
    public class SymbolVerifier : Verifier
    {
        #region Properties

        public List<char> SymbolChars { get; set; }

        #endregion

        #region Constructors

        
        /// <summary>
        /// Initializes a new instance of the <see cref="SymbolVerifier"/> class.
        /// </summary>
        /// <param name="tokenizer">The parent tokenizer.</param>
        public SymbolVerifier(ITokenizer tokenizer) : base(tokenizer)
        {
            SymbolChars = new List<char>();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SymbolVerifier"/> class.
        /// </summary>
        /// <param name="tokenizer">The parent tokenizer.</param>
        /// <param name="symbols">The symbols to recognize.</param>
        public SymbolVerifier(ITokenizer tokenizer, params char[] symbols) : base(tokenizer)
        {
            SymbolChars = new List<char>(symbols);
        }

        #endregion

        #region Verifier

        /// <summary>
        /// Detects if the given char matches the token's pattern.
        /// </summary>
        /// <param name='c'>Char to verify for tokenization.</param>
        /// <returns>
        /// A bool indicating if the given char matches the token's pattern.
        /// </returns>
        public override bool Verify(char c)
        {
            if (Buffer.Length == 0 && SymbolChars.Contains(c))
                return true;
            else
                return false;
        }

        /// <summary>
        /// Creates the token based on the current input-pattern.
        /// </summary>
        /// <returns>
        /// An IToken containing the current input-pattern.
        /// </returns>
        protected override IToken CreateToken()
        {
            return new Token(Buffer, eTokenType.Symbol);
        }

        #endregion
    }
}
